﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace FlyearAssist.Hibernating.DataModel
{
    [System.Runtime.Serialization.DataContract(
        Namespace = "http://NHibernateAssist.Flyear/DataModel",
        IsReference = true)]
    [KnownType(typeof(List<String>))]
    [KnownType(typeof(List<string>))]

    [KnownType(typeof(List<int>))]
    [KnownType(typeof(List<Int16>))]
    [KnownType(typeof(List<Int32>))]
    [KnownType(typeof(List<Int64>))]

    [KnownType(typeof(List<DateTime>))]
    [KnownType(typeof(List<DateTime?>))]

    [KnownType(typeof(List<object>))]
    [KnownType(typeof(List<Object>))]
    public class NCondition
    {
        private String _propertyName;
        [DataMember]
        public String PropertyName
        {
            get { return _propertyName; }
            set { _propertyName = value; }
        }
        private Operation _operate;
        [DataMember]
        public Operation Operate
        {
            get { return _operate; }
            set { _operate = value; }
        }
        private Object _propertyValue;
        [DataMember]
        public Object PropertyValue
        {
            get { return _propertyValue; }
            set { _propertyValue = value; }
        }

        [DataMember]
        public NCondition LNC { get; set; }
        [DataMember]
        public NCondition RNC { get; set; }

        public NCondition() { }
        public NCondition(String propertyName, Operation op, object propertyValue)
        {
            this._propertyName = propertyName;
            this._operate = op;
            this._propertyValue = propertyValue;
        }

        public NCondition(NCondition lNC, Operation op, NCondition rNC)
        {
            if (op != Operation.OR)
            {
                throw new Exception("NCondition Init Error when OP equals 'OR'!");
            }
            Operate = Operation.OR;
            LNC = lNC;
            RNC = rNC;
        }
    }
}
